package com.hl.wechat.demo.websocket;

import com.hl.wechat.demo.entity.User;
import com.hl.wechat.demo.message.WebSocketMessageEntity;

public abstract class ActionHandler {
    private WebSocketManager webSocketManager;
    private WebSocketMessageEntity webSocketMessageEntity;

    public ActionHandler(WebSocketManager webSocketManager, WebSocketMessageEntity webSocketMessageEntity) {
        this.webSocketManager = webSocketManager;
        this.webSocketMessageEntity = webSocketMessageEntity;
    }

    public WebSocketManager getWebSocketManager() {
        return webSocketManager;
    }

    public void setWebSocketManager(WebSocketManager webSocketManager) {
        this.webSocketManager = webSocketManager;
    }

    public WebSocketMessageEntity getWebSocketMessageEntity() {
        return webSocketMessageEntity;
    }

    public void setWebSocketMessageEntity(WebSocketMessageEntity webSocketMessageEntity) {
        this.webSocketMessageEntity = webSocketMessageEntity;
    }

    public abstract void doEvent();

    /**
     * 消息转发
     */
    public static   class MessageForwardHandler extends ActionHandler{
        public MessageForwardHandler(WebSocketManager webSocketManager, WebSocketMessageEntity webSocketMessageEntity) {
            super(webSocketManager, webSocketMessageEntity);
        }

        @Override
        public void doEvent() {
                getWebSocketManager().sendMessage(getWebSocketMessageEntity());
        }
    }
}
